import 'package:architecture/os_size.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:study_demo/ext/menu_ext.dart';
import 'package:study_demo/generated/assets.dart';
import 'package:tolyui/tolyui.dart';

import '../../widgets/text_button.dart';
import 'game_hall_controller.dart';

class GameHallPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<GameHallController>(
        init: GameHallController(),
        builder: (controller) {
          return Scaffold(
            backgroundColor: Colors.transparent,
              body: Container(
                  margin: EdgeInsets.only(top: 20),
                  height: windowHeight,
                  child: Wrap(
                      alignment: WrapAlignment.start,
                      crossAxisAlignment: WrapCrossAlignment.start,
                      spacing: 20,
                      runSpacing: 20,
                      children: [
                        _menu(controller),
                        MyTextButton(
                          text: "教程",
                          confirm: () {
                            controller.goCourse();
                          },
                        ),
                        MyTextButton(
                          text: "角色移动和旋转",
                          confirm: () {
                            controller.goGameCenter1();
                          },
                        ),
                        MyTextButton(
                          text: "键盘事件和手势操作",
                          confirm: () {
                            controller.goGameCenter2();
                          },
                        ),
                        MyTextButton(
                          text: "精灵图片加载方式",
                          confirm: () {
                            controller.goGameCenter3();
                          },
                        ),
                        MyTextButton(
                          text: "动画点触与移动",
                          confirm: () {
                            controller.goGameCenter4();
                          },
                        ),
                        MyTextButton(
                          text: "角色武器发射",
                          confirm: () {
                            controller.goGameCenter5();
                          },
                        ),
                        MyTextButton(
                          text: "视差组件",
                          confirm: () {
                            controller.goGameCenter6();
                          },
                        ),
                        MyTextButton(
                          text: "粒子系统",
                          confirm: () {
                            controller.goGameCenter7();
                          },
                        ),
                      ])));
        });
  }

  _menu(GameHallController controller) {
    return TolyDropMenu(
        width: 180,
        offsetCalculator: boxOffsetCalculator,
        decorationConfig: DecorationConfig(
            isBubble: false, backgroundColor: Color(0xffE0EEF9)),
        onSelect: (value) {
          onSelect(value, controller);
        },
        menuItems: [
          ActionMenu(const MenuMeta(
              router: '2',
              label: 'rogue_shooter',
              ext: MenuDisplayExt(
                  leading: Image(image: AssetImage(Assets.gameGame))))),
          _divider(),
          ActionMenu(const MenuMeta(
              router: '1',
              label: 'padracing',
              ext: MenuDisplayExt(
                  leading: Image(
                image: AssetImage(Assets.gameGame),
              )))),
        ],
        childBuilder: (_, ctrl, __) {
          return MyTextButton(
              text: '官方例子',
              confirm: () {
                ctrl.open();
              });
        });
  }

  _divider() {
    return DividerMenu(height: 0.5);
  }

  onSelect(MenuMeta menu, GameHallController controller) {
    // $message.success(message: '点击了 [${menu.label}] 个菜单');
    print('label${menu.id}');
    controller.goExample(int.parse(menu.id) - 1);
  }
}
